/*
 * ParamStringTest.java
 *
 * Copyright 2007 Christoph Csallner and Yannis Smaragdakis.
 */
package edu.gatech.cc.cnc.params;

import java.util.LinkedList;
import java.util.List;

import junit.framework.TestCase;
import client.Cut;
import client.CutReflect;
import edu.gatech.cc.cnc.firstpass.sym;

/**
 * @author csallner@gatech.edu (Christoph Csallner)
 */
public class ParamStringTest extends TestCase {

  protected final CutReflect cut = new CutReflect(); 
  
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    
    ParamInt.resetSolver();
    ParamRefType.resetEq();
    Param.resetNames(cut.array(), Cut.class);
  }
  
  public void testGetPlan() {
    ParamComplex<String> x = new ParamComplex<String>(String.class, "x");
    ParamComplex<String> y = new ParamComplex<String>(String.class, "y");
    ParamComplex<String> z = new ParamComplex<String>(String.class, "z");
    ParamComplex<String> a = new ParamComplex<String>(String.class, "a");
    List<ParamComplex<?>> params = new LinkedList<ParamComplex<?>>();
    params.add(x);
    params.add(y);
    params.add(z);
    params.add(a);
    
    z.constrain(sym.EQ, x);
    x.constrain(sym.EQ, y);
    
    ParamComplex.prepareSolution(params);
    
    assertEquals("java.lang.String s1 = \"", x.getPlan().text().substring(0, 23));
    assertEquals("java.lang.String s2 = \"", a.getPlan().text().substring(0, 23));
    assertEquals("java.lang.String s3 = s1;", y.getPlan().text());
    assertEquals("java.lang.String s4 = s1;", z.getPlan().text());
  }
}
